package com.zlp.mall.upms.feign;

import com.zlp.mall.core.utils.BeanToUtils;
import com.zlp.mall.core.utils.api.Result;
import com.zlp.mall.upms.api.dto.req.OperLogReq;
import com.zlp.mall.upms.api.feign.FeignOperLogService;
import com.zlp.mall.upms.entity.OperatingLog;
import com.zlp.mall.upms.service.OperatingLogService;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


@Service
@RestController
@Slf4j(topic = "FeignOperLogServiceImpl")
@RequiredArgsConstructor
public class FeignOperLogServiceImpl implements FeignOperLogService {

    private final OperatingLogService operatingLogService;

    @Setter
    private Throwable cause;

    @Override
    @PostMapping("/log")
    public Result<Boolean> saveLog(OperLogReq operLogReq, String from) {

        OperatingLog operatingLog = BeanToUtils.dtoToDo(operLogReq,OperatingLog.class);
        operatingLogService.save(operatingLog);
        log.error("feign 插入日志失败", cause);
        return Result.success(Boolean.TRUE);
    }
}
